package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.ManagementDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Permission;
import com.itheima.service.ManagementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
@Slf4j
public class ManagementImpl implements ManagementService {
  @Autowired
  private ManagementDao managementDao;

    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        //使用分页插件pagehelper
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        //获取分页数据
        Page<Permission> permissions = managementDao.selectByCondition(queryPageBean.getQueryString());
        //封装结果 返回分页对象
        return new PageResult(permissions.getTotal(),permissions.getResult());
    }

    @Override
    public void add(Permission permission) {
        managementDao.add(permission);
    }

    @Override
    public void deleteById(Integer id) {
        managementDao.deleteById(id);
    }

    @Override
    public Permission findById(Integer id) {
        return managementDao.findById(id);
    }

    @Override
    public void edit(Permission permissions) {
     managementDao.edit(permissions);
    }
}
